﻿@using System
@{
    var modules = new[]{
        new {Id=0, Name="People", Title="People", Color="#2773ED", Group="0"},
        new {Id=0, Name="Me", Title="ME", Color="#2773ED", Group="0"},
        new {Id=0, Name="MyScheduler", Title="Calendar", Color="#B11B0D", Group="0"},
        new {Id=0, Name="Administration", Title="Administration", Color="#B11B0D", Group="0"},
        
        
        new {Id=0, Name="Sales", Title="Sales", Color="#502DA4", Group="1"},
        new {Id=0, Name="PointOfSale", Title="Point of sale", Color="#502DA4", Group="1"},
        new {Id=0, Name="Warehouses", Title="Warehouses", Color="#3E3E3E", Group="1"},    
        new {Id=0, Name="Manufacturing", Title="Manufacturing", Color="#1F8DBF", Group="1"},    
        new {Id=0, Name="Products", Title="Products", Color="#1F8DBF", Group="1"},    
        new {Id=0, Name="Accounting", Title="Accounting", Color="#0B4976", Group="1"},    
        new {Id=0, Name="Customer", Title="Customer", Color="#28A61E", Group="1"},    
        new {Id=0, Name="Projects", Title="Projects", Color="#947F6E", Group="1"},
        
        
        new {Id=0, Name="Processes", Title="Processes", Color="#502DA4", Group="2"},
        new {Id=0, Name="RelationshipDiagram", Title="Relationships", Color="#502DA4", Group="2"},
        new {Id=0, Name="Journal", Title="Journal", Color="#B11B0D", Group="2"},    
        new {Id=0, Name="Reports", Title="Reports", Color="#947F6E", Group="2"}
        
    };

    //var colCount = Math.Ceiling((double)modules.Length / 2);
    var gMs = modules.GroupBy(g => g.Group).ToList();

    var maxRow = 2;
    var colCount = gMs.Aggregate(0d, (a, b) => a + Math.Ceiling((double)b.Count() / 2));
    
    
}
<div id="homeGrid" style="height: 100%; overflow: auto" class="jScrollPane">
    <table style="margin: 80px">
        @{
            for (int r = 0; r < maxRow; r++)
            {
            <tr>
                @{
                foreach (var gM in gMs)
                {
                    var splitG = false;
                    var cPg = (int)(Math.Ceiling((double)gM.Count() / maxRow));
                    var items = gM.ToArray();
                    for (int i = cPg * r; i < cPg * (r + 1); i++)
                    {
                        if (i >= items.Length)
                        {
                    <td></td>
                            continue;
                        }
                        var m = items[i];
                        var style = splitG ? "" : "border-left: 30px solid transparent";
                        splitG = true;
                        
                    <td style="@style">
                        <div class="startpageBigIcon" style="" onclick="Meres.openModule('@m.Name');">
                            <div style="color: white;background:@m.Color;height: 100%">
                                <div style="padding: 5px;">
                                    <h1>
                                        @m.Title
                                    </h1>
                                </div>
                            </div>
                        </div>

                    </td>
                    }
                }
                }
            </tr>
            }
        }
    </table>

</div>
